<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>账户安全校验</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/clipboard.js/2.0.8/clipboard.js"></script>
    <script type="text/javascript" src="/js/axios.min.js"></script>
    <script src="//cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>
  </head>

  <body style="background-color: rgb(233, 230, 230)">
    <div style="margin: 20px; padding: 10px; background-color: #fff">
      <div style="padding: 40px; text-align: center">
        <svg
          t="1624347474382"
          class="icon"
          viewBox="0 0 1024 1024"
          version="1.1"
          xmlns="http://www.w3.org/2000/svg"
          p-id="5768"
          width="60"
          height="60"
        >
          <path
            d="M512 1015.232c-147.584 0-422.08-224.64-422.08-436.992V155.136l41.984-0.64a602.24 602.24 0 0 0 191.232-41.024C422.272 73.408 486.208 27.392 486.784 26.88l25.088-18.176 25.216 18.176c0.64 0.448 64.576 46.464 163.712 86.528 96.64 39.04 190.272 40.96 191.296 40.96l41.728 0.64 0.256 423.168c0 212.352-274.496 436.992-422.144 436.992zM175.104 236.16v342.016c0 164.16 239.04 352.192 336.768 352.192 97.792 0 336.768-188.032 336.768-352.192V236.16A688.384 688.384 0 0 1 668.8 192 995.52 995.52 0 0 1 512 112.128c-29.696 18.944-84.608 50.688-156.672 79.872a689.728 689.728 0 0 1-180.096 44.224z m314.24 500.992l-179.2-151.872 55.04-64.512L480.256 618.24l218.176-250.048 64.384 55.68-273.408 313.408z"
            p-id="5769"
            fill="#0e932e"
          ></path>
        </svg>
      </div>

      <div style="text-align: center">
        <div style="padding: 5px; font-weight: bolder">账户安全校验</div>
        <div style="padding: 5px">
          安全码: <span style="color: rgb(21, 105, 35); font-weight: bold" id="safecode"></span>
        </div>

        <button class="btn btn1">复制</button>

        <div style="margin: 10px; border-top: 1px solid #efefef"></div>

        <div
          style="
            margin: 10px;
            font-size: small;
            background: rgb(203, 243, 215);
            border: solid 1px rgb(80, 245, 108);
            padding: 5px;
          "
        >
          复制安全码,发送到群内,继续兑换
        </div>

        <button class="btn" id="clearcache">清空缓存</button>
      </div>
    </div>

    <script>
      var safecode = decodeURIComponent(location.search.replace("?safecode=", ""));
      document.getElementById("safecode").innerText = safecode;

      function clickCopy() {
        copy(safecode).then(function () {
          alert("复制成功, 请到群内粘贴发送,继续兑换");
        });
      }

      new ClipboardJS(".btn1", {
        text: function () {
          return safecode;
        },
      }).on("success", function () {
        alert("复制成功, 请到群内粘贴发送,继续兑换!");
      });

      $("#clearcache").on("click", function () {
        axios.post("/user/clearcache").then(function () {
          alert("清空缓存成功， 请再次复制以上安全码发送到群里绑定");
        });
      });

      function copy(str) {
        return new Promise(function (resolve, reject) {
          var success = false;
          function listener(e) {
            e.clipboardData.setData("text/plain", str);
            e.preventDefault();
            success = true;
          }
          document.addEventListener("copy", listener);
          document.execCommand("copy");
          document.removeEventListener("copy", listener);
          success ? resolve() : reject();
        });
      }
    </script>
  </body>
</html>
